#-*- coding:UTF-8 -*-

import datetime

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

import platmgt.config  as config


from tornado.options import define,options
#from tornado.web import StaticFileHandler


from platmgt.config import PLATMGT_HOME
from platmgt.logger import logger, print_logger_info, set_log_level
from platmgt.web.setting import request_handlers, web_settings


define("port",default=8013,help="run on the given port",type=int)


if __name__ == '__main__':
    set_log_level()
    logger.debug('-'*10 + ' start server ' + str(datetime.datetime.now()) + '-'*10)
    print('PLATMGT_HOME = %s'%PLATMGT_HOME)
    tornado.options.parse_command_line()
    app = tornado.web.Application(request_handlers,**web_settings)
    http_server = tornado.httpserver.HTTPServer(app)
    print(http_server)
    http_server.listen(options.port)
    instance=tornado.ioloop.IOLoop.instance()
    print(instance)
    print_logger_info()
    instance.start()
    logger.debug('-'*10 + '  end  server ' + str(datetime.datetime.now()) + '-'*10)